package com.me.dao.foot;

/**
 * 功能：建造者模式（Builder）
 *
 * @author：dongshibo(F_baisi)
 * @create：2019/1/26/026 11:54
 * @version：2019 Version：1.0
 * @company：老屋新房 Created with IntelliJ IDEA
 */
public class Builder {

	static class Student{
		String name = null;
		int age = 18;
		int sex = 0;

		static class StudentBuilder{
			String name = null;
			int age = 18;
			int sex = 0;

			public StudentBuilder setName(String name) {
				this.name = name;
				return this;
			}

			public StudentBuilder setAge(int age) {
				this.age = age;
				return this;
			}

			public StudentBuilder setSex(int sex) {
				this.sex = sex;
				return this;
			}

			public Student build(){
				return new Student(this);
			}
		}
		public Student(StudentBuilder studentBuilder){
			this.name=studentBuilder.name;
			this.age=studentBuilder.age;
			this.sex=studentBuilder.sex;
		}

		@Override
		public String toString() {
			return "Student{" +
					"name='" + name + '\'' +
					", age=" + age +
					", sex=" + sex +
					'}';
		}
	}

	public static void main(String[] args) {
		Student build = new Student.StudentBuilder().build();
		System.out.println(build);
		System.out.println(new Student.StudentBuilder().setAge(20).build());
		System.out.println(new Student.StudentBuilder().setName("卓航").build());
	}
}
